from django.contrib import admin
from django.urls import path, include
from rest_framework import routers
from finance.views import IncomeViewSet, ExpenseViewSet, BudgetViewSet, UserViewSet, index
from rest_framework.authtoken.views import obtain_auth_token  # 新增
from django.http import HttpResponse

router = routers.DefaultRouter()
router.register(r'incomes', IncomeViewSet)
router.register(r'expenses', ExpenseViewSet)
router.register(r'budgets', BudgetViewSet)
router.register(r'users', UserViewSet)

# 临时视图函数
def placeholder_view(request):
    return HttpResponse("Finance 应用正在运行，请稍后...")

urlpatterns = [
    path('', placeholder_view, name='finance_index'),
    path('admin/', admin.site.urls),
    path('api/', include(router.urls)),
    path('api-auth/', include('rest_framework.urls', namespace='rest_framework')),
    path('api-token-auth/', obtain_auth_token, name='api_token_auth'),
    path('api/records/<int:pk>/', RecordDeleteAPI.as_view(), name='record-delete'),
]